class Solution(object):
    def replaceElements(self, arr):
        """
        :type arr: List[int]
        :rtype: List[int]
        """
        n = len(arr)
        out = [-1] * n
        for i in range(n - 2, -1, -1):
            out[i] = max(out[i + 1], arr[i + 1])
        return out